package com.mutual.reins.interf.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mutual.reins.interf.entity.ReinsPolicyUnit;
import com.mutual.reins.interf.mapper.ReinsPolicyUnitMapper;
import com.mutual.reins.interf.service.IReinsPolicyUnitService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 投保单/保单中间表主表
 服务实现类
 * </p>
 *
 * @author CodeGenerate
 * @since 2021-03-31
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ReinsPolicyUnitServiceImpl extends ServiceImpl<ReinsPolicyUnitMapper, ReinsPolicyUnit> implements IReinsPolicyUnitService {
    @Autowired
    private ReinsPolicyUnitMapper reinsPolicyUnitMapper;

    /**
     * 获取上次批单批单号
     *
     * @param endorNo  批单号
     * @param policyNo 保单号
     * @return 返回上次批单批单号
     */
    @Override
    public List<ReinsPolicyUnit> reinsPolicyUnitList(String policyNo,String endorNo) {
        return reinsPolicyUnitMapper.reinsPolicyUnitList(policyNo,endorNo);
    }

    /**
     * 根据投保单号查询一条数据
     *
     * @param proposalNo 投保单号
     * @return 投保单/保单中间表主表
     */
    @Override
    public ReinsPolicyUnit selectReinsPolicyUnit(String proposalNo) {

        return reinsPolicyUnitMapper.selectReinsPolicyUnit(proposalNo);
    }

    /**
     * 获取该对象Map（key：投保单号 value：ReinsPolicyUnit）
     *
     * @param queryWrapper 查询条件
     * @return 获取该对象Map
     */
    @Override
    public Map<String, ReinsPolicyUnit> selectReinsPolicyUnitMap(QueryWrapper queryWrapper) {
        List<ReinsPolicyUnit> reinsPolicyUnitList = this.list(queryWrapper);
        Map<String,ReinsPolicyUnit> reinsPolicyUnitMap = new HashMap<>(16);
        if(ObjectUtil.isNotNull(reinsPolicyUnitList) && !reinsPolicyUnitList.isEmpty()){
            for(ReinsPolicyUnit reinsPolicyUnit:reinsPolicyUnitList){
                reinsPolicyUnitMap.put(reinsPolicyUnit.getProposalNo(),reinsPolicyUnit);
            }
        }
        return reinsPolicyUnitMap;
    }
}
